package com.yuer.pream.test.utils;

import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class PatternUtils {

    /**
     *  匹配数字-字母 。eg: 10##hitEvent##_AppStart
     */
    public  static  boolean mathStrLine(String str){
        Pattern pattern = Pattern.compile("^[0-9]+"+UserPathConstant.SEPARATION_CHARACTER+"+.*");
        return pattern.matcher(str).matches();
    }

    /**
     *  匹配数字-字母 。eg: 10##hitEvent##_AppStart
     */
    public  static  boolean mathResultLineStrLine(String str){
        Pattern pattern = Pattern.compile("^[0-9]+"+UserPathConstant.SEPARATION_RESULT_CHARACTER+"+.*");
        return pattern.matcher(str).matches();
    }

    /**
     * 匹配 数字-事件
     * @param eventStep
     * @return
     */
    public  static  boolean mathZeroStartEvent(String eventStep){
        Pattern pattern = Pattern.compile("1"+UserPathConstant.SEPARATION_CHARACTER+"+.[^"+UserPathConstant.SEPARATION_CHARACTER+"]*");
        return pattern.matcher(eventStep).matches();
    }
    public  static  boolean mathFirstStartEvent(String eventStep){
        /*Pattern pattern = Pattern.compile("^[1-]+.*");
        return pattern.matcher(eventStep).matches();*/
       return  eventStep.startsWith("1"+UserPathConstant.SEPARATION_CHARACTER);
    }
    public  static  String getSpliteCharater(String flider){
//        return   "'"+flider+"'";
        return   flider;
    }
    public static void main(String[] args) {
        String path1 = "1##_AppStart:NULL";
        String path2 = "1##_AppStart:NULL##_AppStart:NULL";
        String path3 = "1##_AppStart:滁州市##_AppStart:NULL";
        String path4 = "1##_AppStart:NULL##_AppStart:滁州市";
        String path5 = "1##_AppStart##_AppStart";
        String path6 = "3##_AppStart";
        String path7 = "1##_AppStar_tdsdsd:试试";
        String path8 = "3##_AppStar_tdsdsd:试试";
        String path9 = "11##_AppStar_tdsdsd:试试##_AppStart:滁州市";
        System.out.println(mathZeroStartEvent(path1));
        System.out.println(mathZeroStartEvent(path2));
        System.out.println(mathZeroStartEvent(path3));
        System.out.println(mathZeroStartEvent(path4));
        System.out.println(mathZeroStartEvent(path5));
        System.out.println(mathZeroStartEvent(path6));
        System.out.println(mathZeroStartEvent(path7));
        System.out.println(mathZeroStartEvent(path8));
        System.out.println(mathZeroStartEvent(path9));
        StringBuilder ab = new StringBuilder();
        ab.append("(").append("1").append("a").append("123").append("mysql").append(" ").append(")").append("123");
        System.out.println(ab);
        ab = ab.deleteCharAt(ab.toString().lastIndexOf(")"));
        System.out.println(ab);
    }
    public static <T> String parseListToStr3(List<T> list){
//        String result = list.stream().map(String::valueOf).collect(Collectors.joining(","));
        String result = list.stream().map(s -> "\'" + s + "\'").collect(Collectors.joining(", "));
        return result;
    }


    /**
     *  统一方法判断字符串类型
     * @param str
     * @return
     */
    public static boolean  isEmpety(String str){
        return StringUtils.isEmpty(str);
    }

    public static boolean checkEmpetySqlFilter(String globleNewFilter){
        if(PatternUtils.isEmpety(globleNewFilter) || globleNewFilter.equals("()") || globleNewFilter.equals(" (  ) ") || globleNewFilter.equals("(  )")|| globleNewFilter.equals(" () ")){
            return true;
        }
        return false;
    }

    public static void main1(String[] args) {
//
//        List list = new ArrayList();
//        list.add(1231l);
//        list.add(4561l);
//        list.add(7891l);
//        System.out.println(parseListToStr3(list));


    }

}
